var http = require("http");
var io= require('socket.io'); 
var server = http.createServer(function(request, response){
    response.writeHead(200,{"Content-Type":"text/html"});
    response.write("WebSocket Start~~~~~~~~~~~~");
    response.end("");
}).listen(8081);

var socket= io.listen(server); 

// 添加一个连接监听器
socket.on('connection', function(client){ 

  client.on('message',function(event){ 
    client.send("I Tim~!");
    console.log('Received message from client!',event); 
  }); 
  setTimeout(() => {
    client.on('disconnect',function(){ 
      console.log('Server has disconnected'); 
    }); 
  }, 10000);
});